package unversioned;

/**
 * @since Oct 13, 2017
 */
class A {
    public void a() {
        System.out.println("Unversioned.A.a");
    }
}

class B extends A {
    public void b() {
        System.out.println("Unversioned.B.b");
    }
}

public class UpcastingAndDowncasting {
    public static void main(String[] args) {
        /**
         * up casting
         */
        A a1 = new A();
        B b1 = new B();
        //[out]: Unversioned.A.a
        a1.a();
        //[out]: Unversioned.A.a
        b1.a();
        //[out]: Unversioned.B.b
        b1.b();

        /**
         * down casting
         */
        A a2 = new B();
        //[error]: Incompatible types. Required Unversioned.B Found Unversioned.A
        //Unversioned.B b2 = new Unversioned.A();
        B b2 = (B) a2;
        //[out]: Unversioned.A.a
        a2.a();
        //[out]: Unversioned.A.a
        b2.a();
        //[out]: Unversioned.B.b
        b2.b();
    }
}
